﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Simple.Common.Events;
using Simple.Services.Events;
using Simple.Entity.Models;
using Simple.Common.Caching;
using Simple.Common.Infrastructure;

namespace Simple.Service
{
    public class CacheEventConsumer : IConsumer<EntityInserted<Sys_Menu>>, IConsumer<EntityUpdated<Sys_Menu>>, IConsumer<EntityDeleted<Sys_Menu>>, IConsumer<EntityInserted<Sys_Role>>, IConsumer<EntityUpdated<Sys_Role>>, IConsumer<EntityDeleted<Sys_Role>>
    {
        private readonly ICacheManager _cacheManager;

        public CacheEventConsumer(ICacheManager cacheManager)
        {
            _cacheManager = cacheManager;
        }

        /// <summary>
        /// 菜单插入事件
        /// </summary>
        /// <param name="eventMessage"></param>
        public void HandleEvent(EntityInserted<Sys_Menu> eventMessage)
        {
            _cacheManager.Remove(CacheKeys.Sys_Menu);
        }

        /// <summary>
        /// 菜单修改事件
        /// </summary>
        /// <param name="eventMessage"></param>
        public void HandleEvent(EntityUpdated<Sys_Menu> eventMessage)
        {
            _cacheManager.Remove(CacheKeys.Sys_Menu);
        }

        /// <summary>
        /// 菜单删除事件
        /// </summary>
        /// <param name="eventMessage"></param>
        public void HandleEvent(EntityDeleted<Sys_Menu> eventMessage)
        {
            _cacheManager.Remove(CacheKeys.Sys_Menu);
        }

        public void HandleEvent(EntityInserted<Sys_Role> eventMessage)
        {
            _cacheManager.Remove(CacheKeys.Sys_Role);
        }

        public void HandleEvent(EntityUpdated<Sys_Role> eventMessage)
        {
            _cacheManager.Remove(CacheKeys.Sys_Role);
        }

        public void HandleEvent(EntityDeleted<Sys_Role> eventMessage)
        {
            _cacheManager.Remove(CacheKeys.Sys_Role);
        }
    }
}
